﻿using ShiQuan.IotDevice.Business;
using ShiQuan.IotDevice.Entity;
using ShiQuan.WebBase;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web;
using System.Web.Http;

namespace ShiQuan.IotDevice.Web.Api
{
    /// <summary>
    /// 紫外线消毒设备数据上传
    /// </summary>
    public class DeviceDataController : BaseApiController
    {
        /// <summary>
        /// 获取服务器时间
        /// </summary>
        /// <returns></returns>
        public AjaxResult GetTime()
        {
            return this.Success("读取成功", DateTime.Now.ToString());
        }
        /// <summary>
        /// 保存数据
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public AjaxResult SaveData()
        {
            try
            {
                HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];//获取传统context
                HttpRequestBase requestBase = context.Request;//定义传统request对象  
                var source =Newtonsoft.Json.JsonConvert.DeserializeObject<DeviceDataEntity>(requestBase["entity"]);

                DeviceDataBLL service = new DeviceDataBLL();
                service.SaveData(source);

                return this.Success("上传成功");
            }
            catch (Exception ex)
            {
                return this.Error(ex.Message);
            }
        }
    }
}
